<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
</head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<body>
	<div>
		<!-- MAXdiv top -->

		<div>
			<!-- TOPdiv top -->

		</div>
		<!-- TOPdiv end -->

		<div>
			<!-- Centrediv top -->
			<table>
				<!-- 基本注册信息 -->
				<tr>
					<td>用户名：</td>
					<td><input type="text" id="name"></td>
					<td></td>
				</tr>
				<tr>
					<td>密码：</td>
					<td><input type="password" id="password"></td>
					<td></td>
				</tr>
				<tr>
					<td>确认密码：</td>
					<td><input type="password" id="confirmPassword"></td>
					<td></td>
				</tr>
				<tr>
					<td>性别：</td>
					<td><input id="sex" type="radio" checked="checked" value="1" name="sex" />男<input id="sex" type="radio" value="0" name="sex" />女</td>
					<td></td>
				</tr>
				<tr>
					<td>出生年月：</td>
					<td><input type="date" id="bornDate"></td>
					<td></td>
				</tr>
				<tr>
					<td>邮箱地址：</td>
					<td><input type="email" id="email"></td>
					<td></td>
				</tr>
				<tr>
					<td>交易密码：</td>
					<td><input type="password" id="tracePwd"></td>
					<td></td>
				</tr>
				<tr>
					<td>身份证号码：</td>
					<td><input type="text" id="idCard"></td>
					<td></td>
				</tr>
				<tr>
					<td>手机号码：</td>
					<td><input type="number" id="phone"></td>
					<td></td>
				</tr>
				<tr>
					<td>短信验证码：</td>
					<td><input type="number" min="100000" max="999999" id="code"></td>
					<td><input value="获取短信验证码" type="button" onclick="getcode()"></td>
				</tr>
			</table>
			<div>
				<!-- 提交按钮 -->
				<input value="立即注册" type="button" id="submit">
			</div>
		</div>
		<!-- Centrediv end -->

		<div>
			<!-- ENDdiv top -->

		</div>
		<!-- ENDdiv end -->

	</div>
	<!-- MAXdiv end -->
</body>

<script>

	function getcode(){
		
		var phone = $("#phone").val();
		var smsType = "REISTER_SMS";
		var param = {"custMbl" : phone,"smsType" : smsType};
		
		$.ajax({
			type : "post",
			dataType : "json",
			url : "sms/smsSend",
			data : {
				param : JSON.stringify(param)
			},
			success : function(result) {
				if (result.code == "200") {
					alert("短信发送成功，请注意查收");
				} else {
					alert(result.msg);
				}
			},
			error : function(result) {
				alert(result.msg);
			}
		})
	}

	$("#submit").click(function() {
		var custMbl = $("#phone").val();
		var password = $("#password").val();
		var confirmPassword = $("#confirmPassword").val();
		var name = $("#name").val();
		var code = $("#code").val();
		var bornDate = $("#bornDate").val();
		var email = $("#email").val();
		var idCard = $("#idCard").val();
		var tracePwd = $("#tracePwd").val();
		var sex = $('input[name=sex][checked]').val();
		
	//失去焦点事件  TODO
		if (password != confirmPassword) {
			alert("两次密码不一致");
			return;
		}

			var param = {"custMbl" : custMbl,"password" : password,"name" : name,"code":code,"bornDate":bornDate,"email":email,"idCard":idCard,"tracePwd":tracePwd,"sex":sex};
			$.ajax({
				type : "post",
				dataType : "json",
				url : "register.action",
				data : {
					param : JSON.stringify(param)
				},
				success : function(result) {
					if (result.code == "200") {
						alert("注册成功，请登录");
						//window.location.href = "login";
					} else {
						alert(result.msg);
					}
				},
				error : function(result) {
					alert(result.msg);
				}
			})
	});
</script>

</html>